package com.hwadeefsc.springboot.service.impl;

import com.hwadeefsc.springboot.dao.StudentActivitiesDao;
import com.hwadeefsc.springboot.entity.StudentActivities;
import com.hwadeefsc.springboot.service.StudentActivitiesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (StudentActivities)表服务实现类
 *
 * @author makejava
 * @since 2024-07-09 21:43:27
 */
@Service("studentActivitiesService")
public class StudentActivitiesServiceImpl implements StudentActivitiesService {
    @Resource
    private StudentActivitiesDao studentActivitiesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param activityId 主键
     * @return 实例对象
     */
    @Override
    public StudentActivities queryById(Integer activityId) {
        return this.studentActivitiesDao.queryById(activityId);
    }

    /**
     * 分页查询
     *
     * @param studentActivities 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<StudentActivities> queryByPage(StudentActivities studentActivities, PageRequest pageRequest) {
        long total = this.studentActivitiesDao.count(studentActivities);
        return new PageImpl<>(this.studentActivitiesDao.queryAllByLimit(studentActivities, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param studentActivities 实例对象
     * @return 实例对象
     */
    @Override
    public StudentActivities insert(StudentActivities studentActivities) {
        this.studentActivitiesDao.insert(studentActivities);
        return studentActivities;
    }

    /**
     * 修改数据
     *
     * @param studentActivities 实例对象
     * @return 实例对象
     */
    @Override
    public StudentActivities update(StudentActivities studentActivities) {
        this.studentActivitiesDao.update(studentActivities);
        return this.queryById(studentActivities.getActivityId());
    }

    /**
     * 通过主键删除数据
     *
     * @param activityId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer activityId) {
        return this.studentActivitiesDao.deleteById(activityId) > 0;
    }

    @Override
    public List<StudentActivities> getAllQuery() {
        return this.studentActivitiesDao.getAllData();
    }
}
